package path;

import geom.Vector;

import java.util.Iterator;


import processing.core.PApplet;
import shapes.Cross;
import util.Color;

public class DrawCrossPath implements PathDrawer{
	float size;
	int steps;
	public DrawCrossPath(float size, int steps) {
		this.size = size;
		this.steps = steps;
	}

	public void drawPath(Path path, PApplet pa) {
		if(path.keyFrames.size() < 2) return;
		//System.out.println("cross start");
		float stepSize = 1f/steps;
		for(int i = 1; i < path.keyFrames.size(); i++){
			//System.out.println("cross key " + stepSize);
			Vector v1, v2, v3, v4;
			
			if(i >= 2) v1 = path.getKeyFrameByIndex(i-2).getPosition();
			else v1 = path.getKeyFrameByIndex(i-1).getPosition();
			
			v2 = path.getKeyFrameByIndex(i-1).getPosition();
			v3 = path.getKeyFrameByIndex(i).getPosition();
			
			if(i < path.keyFrames.size() - 1) v4 = path.getKeyFrameByIndex(i+1).getPosition();
			else v4 = path.getKeyFrameByIndex(i).getPosition();
			
			for(float s = 0; s < 1; s += stepSize){
				//System.out.println("cross step " + s);
				float x = pa.curvePoint(v1.x, v2.x, v3.x, v4.x, s);
				float y = pa.curvePoint(v1.y, v2.y, v3.y, v4.y, s);
				float z = pa.curvePoint(v1.z, v2.z, v3.z, v4.z, s);
				pa.pushMatrix();
				pa.translate(x, y, z);
				Cross.draw(pa, size, new Color(110, 30, 230));
				pa.popMatrix();
			}
		}
		//System.out.println("cross done");
		
	}

	public void keyAdded(Path p) {
		// TODO Auto-generated method stub
		
	}
	public void keysAdded(Path p, int amount) {
		// TODO Auto-generated method stub
		
	}

	public void keyRemoved(Path p, int i) {
		// TODO Auto-generated method stub
		
	}

}
